package com.ims.excel.x01hello;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;

/**
 * @author gaoxu
 * @date 2019-07-04 17:31
 * @description ... 类
 */
public class HelloExcel {

    public static void main(String[] args) {

        try {
            /**
             * 读和写
             *      1.读
             *      2.写
             */

            /**
             * 1.读
             */
            //97-2007
            File file = new File("x03-office/x0301-poi/hellExcelV97-2007.xls");
            InputStream inputStream = new FileInputStream(file);
            Workbook wb = new HSSFWorkbook(inputStream);
            System.out.println(wb.getSheetAt(0).getSheetName());
            System.out.println(wb.getSheetAt(1).getSheetName());
            //2007以上
            /*File file = new File("x03-office/x0301-poi/hellExcelV2007.xls");
            InputStream inputStream = new FileInputStream(file);
            Workbook wb = new XSSFWorkbook(inputStream);
            System.out.println(wb.getSheetAt(0).getSheetName());
            System.out.println(wb.getSheetAt(1).getSheetName());*/
            /**
             * 2.写
             */
            //97-2007
            /*Workbook workbook = new HSSFWorkbook();
            File file = new File("x03-office/x0301-poi/hellExcelV97-2007.xls");
            OutputStream outputStream = new FileOutputStream(file);
            workbook.createSheet("第一个Sheet页");
            workbook.createSheet("第二个Sheet页");
            workbook.write(outputStream);
            outputStream.close();*/
            //2007以上
            /*Workbook wb = new XSSFWorkbook();
            File file = new File("x03-office/x0301-poi/hellExcelV2007.xls");
            OutputStream outputStream = new FileOutputStream(file);
            wb.createSheet("第一个Sheet页");
            wb.createSheet("第二个Sheet页");
            wb.write(outputStream);
            outputStream.close();*/
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
